#pragma once

#define MAX_BOX_X_HALF 15
#define MAX_BOX_Y_HALF 1
#define MAX_BOX_Z_HALF 15
#define MAX_BOMB_COUNT 10

namespace BombBox
{
	class GameItem;
	class GameRoom;
	class SceneConfig;

#define s_pBoxPlacerRuler ( BombBox::BoxPlacerRuler::getSingletonPtr() )

	class BOXUTIL
	{
	public:
		static bool grid( float x, float y, float z, int& ix, int& iy, int& iz );

		static  irr::core::vector3df getRenderPos( int x, int y, int z );
	};

	class BoxPlacerRuler : public OSLib::Singleton<BoxPlacerRuler>
	{
	public:
		BoxPlacerRuler( void );
		~BoxPlacerRuler( void );

	public:
		bool clear( SceneConfig* pConfig );

		void loadConfig( SceneConfig* pConfig );
		void saveConfig( SceneConfig* pConfig );

	public:
		bool canPlace( const irr::core::vector3df& vPos, SceneConfig* pConfig );
		bool addBox( const irr::core::vector3df& vPos, GameItem* pBox, SceneConfig* pConfig );
		bool addBomb( const irr::core::vector3df& vPos, GameItem* pBomb, SceneConfig* pConfig );
		void remove( GameItem* pItem );
		void doBomb( GameItem* pItem );

	public:
		GameItem* getGameItem( int x, int y, int z );
		void onBoxBomb( int x, int y, int z );

	protected:
		friend class GameItem;
		SceneConfig*	m_pConfig;
		GameItem*		vBoxs[MAX_BOX_X_HALF*2+1][MAX_BOX_Y_HALF*2+1][MAX_BOX_Z_HALF*2+1];

		int				vBombs[MAX_BOMB_COUNT];
	};
}